package be.jaisy.ui.gwt.client.util;

import java.util.Date;

public class DateAndTime extends Date {

	private static final long serialVersionUID = 9020390805239864856L;

	//private static final String DATE_FORMAT_EXPR = "dd/MM/yyyy HH:mm:ss:S";

	public DateAndTime(Date date) {
		super(date.getTime());
	}

	public int compareTo(Date arg0) {
		return super.compareTo(arg0);
	}

	public String toString() {
		return this.format(this);
	}

	/*
	 * formatDate
	 * 
	 * Formats the date in "dd/MM/yyyy HH:mm:ss:S" format
	 * 
	 * @param (Date to be formatted) @return String
	 */
	private String format(Date date) {
		StringBuffer dateStr = new StringBuffer();
		if (date.getDate() < 10) {
			dateStr.append("0");
		}
		dateStr.append(date.getDate());
		dateStr.append("/");
		dateStr.append(date.getMonth());
		dateStr.append("/");
		dateStr.append((date.getYear() + 1900));
		dateStr.append(" ");
		dateStr.append((date.getHours()));
		dateStr.append(":");
		dateStr.append((date.getMinutes()));
		dateStr.append(":");
		dateStr.append((date.getSeconds()));
		return dateStr.toString();
	}
}
